from flask import Blueprint, render_template, request
from .models import *

blue = Blueprint('app', __name__, template_folder='templates')


@blue.route('/')
@blue.route('/book_index')
@blue.route('/index')
def index():
    pr_str = '这是我的首页，地址为：book_index 或者 index 或者  '
    return render_template('book_index.html', pr_str=pr_str)


@blue.route('/book_list')
def book_list():
    pr_str = '这是我的图书列表，地址为：book_list'
    books = Book.query.all()
    return render_template('book_list.html', pr_str=pr_str, books=books)


@blue.route('/book_detail/<int:book_id>')
def book_detail(book_id):
    pr_str = '这是具体的图书详情，地址为：/book_detail/<int:book_id> '
    book = Book.query.get(book_id)
    return render_template('book_detail.html', pr_str=pr_str, book=book)


@blue.route('/author_detail/<int:author_id>')
def author_detail(author_id):
    pr_str = '这是作者的详情页，地址为：/author_detail/<int:author_id> '
    author = Author.query.get(author_id)
    return render_template('author_detail.html', pr_str=pr_str, author=author)


@blue.route('/publisher_detail/<int:publisher_id>')
def publisher_detail(publisher_id):
    pr_str = '这是出本社的详情页，地址为：/publisher_detail/<int:publisher_id> '
    publisher = Publisher.query.get(publisher_id)
    return render_template('publisher_detail.html', pr_str=pr_str, publisher=publisher)
